package com.okay.monitoring

import android.os.Bundle
import android.os.Handler
import android.os.Looper
import android.os.Message
import android.util.Log
import android.widget.Button
import android.widget.Toast
import androidx.fragment.app.FragmentActivity
import com.okay.testclass.R
import com.okay.util.sysInfo

/**
 * 一个监控 内存 cpu ram rom 的activity
 */

class MonitoringActivity :FragmentActivity(){

    var ii=0
    var barrageView:BarrageView? = null
    var isWhile = false

    override fun onCreate(savedInstanceState: Bundle?) {
        super.onCreate(savedInstanceState)
        setContentView(R.layout.activity_monitoring)

        barrageView = findViewById<BarrageView>(R.id.barrage)
        var start = findViewById<Button>(R.id.start)
        var suspended = findViewById<Button>(R.id.suspended)
        var stop = findViewById<Button>(R.id.stop)
        var add = findViewById<Button>(R.id.add)

        start.setOnClickListener {
//            barrageView?.startView()
            isWhile = true
            Thread{
                while (isWhile){
                    Thread.sleep(200)
                    handler.sendMessage(Message())
                }

            }.start()
        }
        stop.setOnClickListener {
//            barrageView?.stopView()
            isWhile = false
        }
        suspended.setOnClickListener {
            barrageView?.suspendedView()
        }
        add.setOnClickListener {
            barrageView?.addData(UserData(ii++.toString()))
        }
        barrageView?.setOnClickLisenter1(object : BarrageView.OnClickLisenter1{
            override fun clock(userData: UserData) {
                Toast.makeText(this@MonitoringActivity,userData.signature, Toast.LENGTH_SHORT).show()
            }

        })


        sysInfo().sss()

    }

    var handler = object :Handler(Looper.myLooper()!!){
        override fun handleMessage(msg: Message) {
            super.handleMessage(msg)
            barrageView?.addData(UserData(ii++.toString()))
        }
    }

    override fun onPause() {
        super.onPause()
        isWhile = false
    }

}